package com.scf.contract.controller;

import com.scf.contract.entity.Borrowing;
import com.scf.contract.entity.Contract;
import com.scf.contract.service.ContractService;
import com.scf.uitl.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author author
 * @create 2021-11-10-20:43
 */
@RestController
@RequestMapping("/contract")
public class ContractController {
    @Resource
    ContractService contractService;
   //查询所有合同信息
    @GetMapping("/all")
    public ResponseResult selectAll(){
        List<Contract> contracts = contractService.selectAll();
        ResponseResult responesResult = new ResponseResult();
        responesResult.setCode(200);
        responesResult.setData(contracts);
        return responesResult;
    }
    //根据id查询合同信息
    @GetMapping("/getContractByBoid/{boid}")
    public ResponseResult getContractByBoid(@PathVariable int boid){
        Contract contractByBoid = contractService.getContractByBoid(boid);
        ResponseResult responesResult = new ResponseResult();
        responesResult.setCode(200);
        responesResult.setData(contractByBoid);
        return responesResult;
    }

    //增加合同信息
    @PostMapping("/addContract")
    public ResponseResult addContract(@RequestBody Contract contract){
        Contract c = new Contract();
        c.setLenderinformation(contract.getLenderinformation());
        c.setAccountinginstitute(contract.getAccountinginstitute());
        c.setPaymentaccount(contract.getPaymentaccount());
        c.setContractnumber(contract.getContractnumber());
        c.setDatesigning(contract.getDatesigning());
        c.setCustomername(contract.getCustomername());
        c.setSigningaddress(contract.getSigningaddress());
        c.setLoanamount(contract.getLoanamount());
        c.setProductname(contract.getProductname());
        c.setRepaymentmethod(contract.getRepaymentmethod());
        c.setTermtype(contract.getTermtype());
        c.setTerm(contract.getTerm());
        c.setMonthlyrate(contract.getMonthlyrate());
        c.setProcessingfees(contract.getProcessingfees());
        c.setDefaultrate(contract.getDefaultrate());
        c.setBorrower(contract.getBorrower());
        c.setUsageloan(contract.getUsageloan());
        c.setEmail(contract.getEmail());
        contractService.addContract(c);
        ResponseResult responesResult = new ResponseResult();
        responesResult.setCode(200);
        responesResult.setData(null);
        return responesResult;

    }
    //根据企业id外键查询企业信息
    @GetMapping("/getContractByBwid/{bwid}")
    public ResponseResult getContractByBwid(@PathVariable int bwid){
        Borrowing contractByBwid = contractService.getContractByBwid(bwid);
        ResponseResult responesResult = new ResponseResult();
        responesResult.setCode(200);
        responesResult.setData(contractByBwid);
        return responesResult;
    }


}
